﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.ServiceModel;

namespace SMS.Service
{
    partial class SMSService : ServiceBase
    {
        public SMSService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            SMSStart();
        }

        protected override void OnStop()
        {
            SMSStop();
        }

        static ServiceHost m_service;
        static void SMSStart()
        {
            if (m_service == null)
            {
                m_service = new ServiceHost(typeof(CommSMSService));
            }
            try
            {
                m_service.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        static void SMSStop()
        {
            if (m_service != null)
            {
                if (m_service.State == CommunicationState.Opening)
                {
                    m_service.Close(new TimeSpan(10000));
                }
            }
            m_service = null;
        }
    }
}
